<?php
$nbEltCmd=nb_elt_commande($_SESSION['commandeEnCours']);

if ($nbEltCmd[0] >1) {

    if (isset($_GET['idParticipation'])) {
        $Shaparticipation = $_GET['idParticipation'];

        $trouve = false;

        $rqt_id_participation = "SELECT p.idParticipation, c.idUtilisateur from Participation as p LEFT JOIN Commande as c ON p.idCommande=c.idCommande";
        $res_id_participation = mysql_query($rqt_id_participation);
        while (($trouve == false) && (list($idParticipation, $idUtilisateur) = mysql_fetch_array($res_id_participation))) {
            if (sha1($idParticipation) == $Shaparticipation && $idUtilisateur == $_SESSION['idUtilisateur']) {
                $trouve = true;
            }
        }

        if ($trouve==true){
        $rqt_delete_participation = "DELETE FROM Participation WHERE idParticipation=" . $idParticipation;
        mysql_query($rqt_delete_participation);
        }
    }


    if (isset($_GET['idCommandeRDV'])) {
        $ShacommandeRDV = $_GET['idCommandeRDV'];

        $trouve = false;

        $rqt_id_commandeRDV = "SELECT p.idCommandeRDV, c.idUtilisateur from CommandeRDV as p LEFT JOIN Commande as c ON p.idCommande=c.idCommande";
        $res_id_commandeRDV = mysql_query($rqt_id_commandeRDV);
        while (($trouve == false) && (list($idCommandeRDV, $idUtilisateur) = mysql_fetch_array($res_id_commandeRDV))) {
            if (sha1($idCommandeRDV) == $ShacommandeRDV && $idUtilisateur == $_SESSION['idUtilisateur']) {
                $trouve = true;
            }
        }
        
        if ($trouve==true){
        $rqt_delete_commandeRDV = "DELETE FROM CommandeRDV WHERE idCommandeRDV=" . $idCommandeRDV;
        mysql_query($rqt_delete_commandeRDV);
        }
    }

    if (isset($_GET['idCommandePlateforme'])) {
        $ShacommandeAP = $_GET['idCommandePlateforme'];
        
        $trouve = false;
        
        $rqt_id_commandeAP = "SELECT p.idCommandeAccesPlateforme, c.idUtilisateur from CommandeAccesPlateforme as p LEFT JOIN Commande as c ON p.idCommande=c.idCommande";
        $res_id_commandeAP = mysql_query($rqt_id_commandeAP);
        while (($trouve == false) && (list($idCommandeAP, $idUtilisateur) = mysql_fetch_array($res_id_commandeAP))) {
           // echo $ShacommandeAP.' : '.sha1($idCommandeAP);
            if (sha1($idCommandeAP) == $ShacommandeAP && $idUtilisateur == $_SESSION['idUtilisateur']) {
                echo ':true<br>';
                $trouve = true;
            }
        }
        //echo $trouve;
        if ($trouve==true){

        $rqt_delete_commandeAP = "DELETE FROM CommandeAccesPlateforme WHERE idCommandeAccesPlateforme=" . $idCommandeAP;
        mysql_query($rqt_delete_commandeAP);
        }
    }
    maj_cout_commande($_SESSION['commandeEnCours']);
    header("Location: index.php?page=confirm_commande");
}else{
    header("Location: index.php?page=supprimer_Commande&cmd=".sha1($_SESSION['commandeEnCours']));
}
?>